package sk.gtug.pivoplus.malepivo;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import sk.gtug.pivoplus.malepivo.utils.Http;

/**
 * @author Tomas
 * 
 * equivalent off application controller
 */
public class Application extends android.app.Application {

	public static final String SERVICE_URL = "http://pluspivo.appspot.com/pivo-plus-rest/pivo/";

	/**
	 * The default search radius when searching for pubs nearby.
	 */
	public static final int DEFAULT_RADIUS = 150;

	/**
	 * The maximum distance the user should travel between location updates.
	 */
	public static final int MAX_DISTANCE = DEFAULT_RADIUS / 2;

	/**
	 * The maximum time that should pass before the user gets a location update.
	 */
	public static final long MAX_TIME = 900000;  // 15 min

	protected String appId = null;

	// Persistent preferencies
	public static final String PREFS_KEY_CITY = "city";
	public static final String PREFS_KEY_COUNTRY = "country";

	@Override
	public void onCreate() {
		super.onCreate();
		
		// TODO: uncoment later , for now use hardcoded value 1
		// creating app id
		// looks like it does not work with emulator
		/*String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
		UUID uuid = UUID.randomUUID();
		if (android_id != null) {
			appId = android_id;
		} else {
			appId = uuid.toString();
		}*/
		appId = "1";
	}
	
	// ---------------------------------------------------------------------------------
	//
	// Service calls
	//
	// ---------------------------------------------------------------------------------
	
	/**
	 * calls evaluate service
	 * @return void
	 */
	public void evaluteServiceCall(String id, String evalTypeId, String rating, String comment)
	{
		// krcma/{id}/{userId}/{evalTypeId}/{value}/{comment}
		String url = SERVICE_URL;
		url += "krcma/";
		/*url += id + "/";
		url += appId + "/";
		url += evalTypeId + "/";
		url += rating + "/";
		url += comment;
		
		String result = Http.get(url);*/
		
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
        nameValuePairs.add(new BasicNameValuePair("id", id));
        nameValuePairs.add(new BasicNameValuePair("userId", appId));
        nameValuePairs.add(new BasicNameValuePair("evalTypeId", evalTypeId));
        nameValuePairs.add(new BasicNameValuePair("value", rating));
        nameValuePairs.add(new BasicNameValuePair("comment", " "));
		
        HttpEntity result = Http.postData(url, nameValuePairs);
	}
}
